package com.grf.hadoop.flow_bean;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * 偏移量
 * 一行文本
 * 输入数据类型
 * 输出数据类型
 */
public class FlowMapper extends Mapper<LongWritable, Text, Text, FlowBean> {


    private FlowBean v = new FlowBean();
    private Text k = new Text();

    @Override
    protected void map(LongWritable key, Text value, Context context)
            throws IOException, InterruptedException {
        //获取一行
        String line = value.toString();
        //切割
        String[] fields = line.split(" ");
        //封装对象
        k.set(fields[0]);
        long upFlow = Long.parseLong(fields[1]);
        long downFlow = Long.parseLong(fields[2]);

        v.setDownFlow(downFlow);
        v.setUpFlow(upFlow);
        v.setSumFlow(upFlow + downFlow);
        //写出
        context.write(k,v);
    }
}
